package com.fbinggun.fbinggunutil.statistics.command;

import com.fbinggun.fbinggunutil.FBinggunUtil;
import com.fbinggun.fbinggunutil.command.ACommand;
import com.fbinggun.fbinggunutil.command.MainCommand;
import com.fbinggun.fbinggunutil.statistics.PlayerStatistics;
import com.fbinggun.fbinggunutil.statistics.StatisticsAPI;
import com.fbinggun.fbinggunutil.statistics.StatisticsInfo;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

public class Add extends ACommand {
      StatisticsAPI api;
    public Add(MainCommand mainCommand) {
        super(mainCommand);
        api= FBinggunUtil.plugin.getStatistMain().getStatApi();
    }

    @Override
    public String getPresentation() {
        return "&e/"+getMainCommand().getCmd()+" "+getId()+" [玩家名] [id] [值] &7为玩家添加统计值";
    }
    @Override
    public boolean isOp() {
        return true;
    }

    @Override
    public String getPermission() {
        return null;
    }

    @Override
    public String getId() {
        return "add";
    }

    //statistics add [玩家名] [id] [v]
    @Override
    public boolean run(CommandSender sender, String[] args) {
        if(args.length==4){
            OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
            String id =args[2];
            StatisticsInfo info =api.getDefaultInfo(id);
            if(info==null){
                getPlugin().sendPlayerMsg(sender, "&c此统计信息不存在 你可以尝试创建统计信息");
                return false;
            }
            api.addSValue(player,id,args[3]);
            getPlugin().sendPlayerMsg(sender, "&a玩家 &f" + player.getName() + " &f "+id+" &a统计数据 &b+"+args[3]+" &a当前数据为: &b"+api.getPlaceholder(player,id));
        }
        return false;
    }

    @Override
    public List<String> getTAB(int l, CommandSender sender, String[] args) {
        List<String> list= super.getTAB(l, sender,args);
        if(l==2){
            for(Player player:Bukkit.getOnlinePlayers()){
                list.add(player.getName());
            }
        }
        if(l==3){
                list.addAll(FBinggunUtil.plugin.getStatistMain().getProject().map.keySet());
        }

        return list;
    }

    @Override
    public boolean isPlayer() {
        return false;
    }

}
